/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.gzchengguo.cn
* 注意：
* 本软件为www.gzchengguo.cn开发研制，未经购买不得商用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package link.chengguo.orangemall.modules.shop.rest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import link.chengguo.orangemall.api.ApiResult;
import link.chengguo.orangemall.modules.domain.OrangeArticleCategory;
import link.chengguo.orangemall.modules.service.OrangeArticleCategoryService;
import link.chengguo.orangemall.modules.wechat.domain.OrangeArticle;
import link.chengguo.orangemall.modules.wechat.service.OrangeArticleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章 前端控制器
 * </p>
 *
 * @author chengguo
 * @since 2019-10-02
 */
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/articleCategory")
@Api(value = "文章分类模块", tags = "商城:文章分类模块", description = "文章分类模块")
public class ArticleCategoryController {

    private final OrangeArticleCategoryService articleCategoryService;
    private final OrangeArticleService articleService;


    /**
    * 获取文章文章详情
    */
    @GetMapping("/details/{id}")
    @ApiOperation(value = "文章分类详情",notes = "文章分类详情")
    public ApiResult<IPage<OrangeArticle>> getOrangeArticle(@PathVariable Integer id,Page page){
        IPage<OrangeArticle> articlePage = articleService.page(page,new QueryWrapper<OrangeArticle>().eq("cid", id));
        return ApiResult.ok(articlePage);
    }

    /**
     * 文章列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "文章分类列表",notes = "文章分类列表")
    public ApiResult<List<OrangeArticleCategory>> getOrangeArticlePageList(){
        return ApiResult.ok(articleCategoryService.list(new QueryWrapper<OrangeArticleCategory>().eq("status",true)));
    }

}

